#include<iostream>
using namespace std;
#include<vector>
#include<algorithm>
class Solution {
public:
    vector<vector<int>> ans;
    vector<int> path;
    int sum = 0;
    void dfs(vector<int>& candidates, int target, int now) {
        if (sum >= target) {
            if (sum == target)
                ans.push_back(path);
            return;
        }
        for (int i = now; i < candidates.size(); ++i) {
            while (i > now && i < candidates.size() && candidates[i] == candidates[i - 1])
                ++i;
            if (i == candidates.size())
                break;
            sum += candidates[i];
            path.push_back(candidates[i]);
            dfs(candidates, target, i + 1);
            path.pop_back();
            sum -= candidates[i];
        }
        return;
    }
    vector<vector<int>> combinationSum2(vector<int>& candidates, int target) {
        sort(candidates.begin(), candidates.end());
        for (int i = 0; i < candidates.size(); ++i) {
            while (i > 0 && i < candidates.size() && candidates[i] == candidates[i - 1])
                ++i;
            if (i == candidates.size())
                break;
            sum = candidates[i];
            path.push_back(candidates[i]);
            dfs(candidates, target, i + 1);
            path.pop_back();
        }
        return ans;
    }
};